/*************************************
Copyright 2011 Chinua Iloabachie, Pradnya Khutafale, Siyi Liu, Junichi Suzuki, and The University of Massachusetts, Boston (http://code.google.com/p/tabletuml/)


Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
 
*************************************/




package touchMe.baseClass;

import touchMe.Gesture.MoveClass;
import touchMe.Gesture.MovePolicy;
import touchMe.Gesture.MoveRelation;
import touchMe.Gesture.MoveUseCase;
import touchMe.Gesture.MoveActor;

public class Element {
	
	
	private float x;
	private float y;
	private float w;
	private float h;
	private StringBuffer panelAttributes;
	private StringBuffer additionalAttributes;
	private ElementType type;
	private MovePolicy policy;
	
	public Element()
	{
		
	}
	public Element(float x1,float y1, float w1, float h1, ElementType type)
	{
		this.x=x1;
		this.y=y1;
		this.w=w1;
		this.h=h1;
		this.type=type;
	}
	
	public MovePolicy getPolicy() {
		return policy;
	}
	public void setPolicy(MovePolicy policy) {
		this.policy = policy;
	}
	public float getX() {
		return x;
	}
	public void setX(float x) {
		this.x = x;
	}
	public float getY() {
		return y;
	}
	public void setY(float y) {
		this.y = y;
	}
	public float getW() {
		return w;
	}
	public void setW(float w) {
		this.w = w;
	}
	public float getH() {
		return h;
	}
	public void setH(float h) {
		this.h = h;
	}
	public StringBuffer getPanelAttributes() {
		return panelAttributes;
	}
	public void setPanelAttributes(StringBuffer panelText) {
		this.panelAttributes = panelText;
	}
	public StringBuffer getAdditionalAttributes() {
		return additionalAttributes;
	}
	public void setAdditionalAttributes(StringBuffer additionalAttributes) {
		this.additionalAttributes = additionalAttributes;
	}
	public ElementType getType() {
		return type;
	}
	public void setType(String sType) {
		if(sType.equals(Constants.classType))
		{	 
			this.type=ElementType.CLASS;
			policy= new MoveClass(this);
		}	
		if(sType.equals(Constants.actorType)){
			this.type = ElementType.ACTOR;
			policy=new MoveActor(this);
		}
		if(sType.equals(Constants.relationType))
		{   
			// relation type is based on panel attribute.So default
			  // type of relation is set to simple association. 
			
			if(this.panelAttributes==null)
			{
				this.type=ElementType.TEMPORARY_ASSOCIATION;
				return;
			}	
			
			  // when panel
			  // attribute is set, reset the type attribute of relation
			String strPanelAttr=this.panelAttributes.toString().trim();
			if(strPanelAttr.equals(Constants.inheritPanelAttr))
			this.type=ElementType.INHERITANCE;
			
			else if(strPanelAttr.equals(Constants.implementPanelAttr))
			this.type = ElementType.IMPLEMENTATION;
			
			else
				this.type = ElementType.SIMPLE_ASSOC;
			
			policy=new MoveRelation(this);
		}	
		if(sType.equals(Constants.usecaseType))
		{	
			this.type = ElementType.USECASE;
			policy= new MoveUseCase(this);
		}	
	}
	
	public  void reCalculateCoOrdinates()
	{
		
	}
}
